<template>
	<view class="page" :style="themeColor">
		<view class="flex benben-position-layout flex flex-wrap align-center platformMessage_flex_0"
			:style="{height:(64+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class='flex flex-wrap align-center justify-between flex-sub platformMessage_fd0_0'>
				<view class='flex flex-wrap align-center platformMessage_fd0_0_c0'
					@tap.stop="openModel">
					<text class='fu-iconfont2  platformMessage_fd0_0_c0_c0'>&#xE794;</text>
				</view>
				<view class='flex flex-wrap align-stretch justify-center'>
					<text class='platformMessage_fd0_0_c1_c0'>汇总强化</text>
				</view>
				<view class='flex flex-wrap align-center platformMessage_fd0_0_c0'></view>
			</view>

		</view>
		<view :style="{height: (64+StatusBarRpx)+'rpx'}"></view>
		
		<view class="loading_css" v-if="isShow">
			<uv-loading-icon size="24" mode="circle" color="#4087FD" :show="true"></uv-loading-icon>
			<view>加载中</view>
		</view>

		<view class="flex flex-direction align-stretch benben-flex-layout platformMessage_flex_1" v-else>
			<view class="intensify">
				<view class="forget_list">
					<view class="forget_item" :class="k == (list.length - 1) ? 'no_line' : ''" v-for="(v, k) in list" @tap.stop="clickWord(k)">
						<view class="item_content">
							<view class="see_word">
								<view class="see_word_left">
									<rich-text v-if="v.clickNum == 0" :nodes="fileText(v.word, v.syllable)"></rich-text>
									<rich-text v-if="((v.clickNum % 3) != 0) && v.clickNum != 0" class="select_word" :nodes="fileText(v.word, v.syllable)"></rich-text>
									<rich-text style="opacity: 0;color: #fff;" v-if="(v.clickNum % 3) == 0" :nodes="fileText(v.word, v.syllable)"></rich-text>
									<!-- <text v-if="v.clickNum == 0">{{v.word}}</text>
									<text v-if="v.clickNum == 1 || v.clickNum == 2" class="select_word">{{v.word}}</text>
									<image v-if="v.clickNum == 1" class="see_img" :src='STATIC_URL+"40.png"' mode=""></image> -->
									<text v-if="v.clickNum == 2 || v.clickNum == 5 || v.clickNum == 8 || v.clickNum == 11" class="select_word_explain">{{v.c_word}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				
			</view>
		</view>
		
		<uv-modal width="300rpx" :showCancelButton="true" :closeOnClickOverlay="false" confirmColor="#4087FD"
			ref="modal" title="提示" content='是否结束强化单词？' align="center" :textStyle="{fontSize: 20 + 'px'}"
			@confirm="confirm"></uv-modal>
			
		<view class="noData" v-if="list.length == 0  && !isShow">
			<image :src='STATIC_URL+"no.png"' mode="aspectFill"></image>
		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'
	import {highlightedText} from "@/common/utils/utils.js"
	export default {
		components: {},


		data() {
			return {
				"list": [],
				"tabs": 1,
				"aid": "",  // 记录id
				"isShow": true,
				"innerAudioContext": null,
				"languageType": 1,  // 1美式  2法式
				"clickNum": 0, // 单词点击次数
				"one_index": -1,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {aid} = options;
			if (aid !== undefined) this.aid = aid;
			this.getWord();
		},
		onUnload() {

		},
		onReady() {
			this.innerAudioContext = uni.createInnerAudioContext();
		},
		onShow() {
			this.languageType = uni.getStorageSync('languageType');
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			fileText(text, syllable) {
				return highlightedText(text, syllable);
			},
			selectTabs(type) {
				this.tabs = type;
			},
			getWord() {
				let url = "";
				url = global.apiUrls.post657183034d0ab;
				this.$api.post(url, {
					record_id: this.aid
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 1) {
						this.list = res.data.data.list;
						if (this.list.length > 0) {
							this.list.forEach((v, k) => {
								v.clickNum = 0;
							})
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			
			// 提交单词训练  post6571840105068
			submit() {
				let word_id = "";
				word_id = this.list[this.one_index].aid;
				let url = "";
				url = global.apiUrls.post6571840105068;
				this.$api.post(url, {
					wordlist_id: word_id,
					record_id: this.aid
				}).then(res => {
					if (res.data.code == 1) {
						this.list.splice(this.one_index, 1);
						this.one_index = -1;
						this.$forceUpdate();
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			
			// 选择的单词
			selectWord(index) {
				this.one_index = index;
				this.$forceUpdate();
			// 	if (index == 0) {
			// 		if (index1 == 0) {
			// 			this.activeWord = word;
			// 			this.one_index = index;
			// 			this.two_index = index1;
			// 			this.is_click = true;
			// 		} else {
			// 			let list_index = false;
			// 			for (var i = 0; i < index1; i++) {
			// 				if (this.paragraph_data[index].word_info[i].color == 1) {
			// 					list_index = true;
			// 					break;
			// 				}
			// 			}
			// 			if (!list_index) {
			// 				this.activeWord = word;
			// 				this.one_index = index;
			// 				this.two_index = index1;
			// 				this.is_click = true;
			// 			} else {
			
			// 			}
			// 		}
			// 	} else {
			// 		let list_index = false;
			// 		for (var i = 0; i < this.paragraph_data[index - 1].word_info.length; i++) {
			// 			if (this.paragraph_data[index].word_info[i].color == 1) {
			// 				list_index = true;
			// 				break;
			// 			}
			// 		}
			// 		if (!list_index) {
			// 			this.activeWord = word;
			// 			this.one_index = index;
			// 			this.two_index = index1;
			// 			this.is_click = true;
			// 		} else {
						
			// 		}
			// 	}
			},
			// 单词点击次数
			clickWord(index) {
				if (index != this.one_index) {
					if (this.list.length > 0) {
						this.list.forEach((v, k) => {
							v.clickNum = 0;
						})
					}
				}
				this.one_index = index;
				this.list[index].clickNum += 1;
				if (this.innerAudioContext) {
					this.innerAudioContext.destroy();
				}
				this.innerAudioContext = null;
				this.innerAudioContext = uni.createInnerAudioContext();
				this.innerAudioContext.autoplay = true;
				if (this.languageType == 1) {
					this.innerAudioContext.src = this.list[this.one_index].american_accent;
					
				} else {
					this.innerAudioContext.src = this.list[this.one_index].british_accent;
				}
						
				this.innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				this.innerAudioContext.onError((res) => {
					this.$message.info('播放失败，请重试');
					this.list[index].clickNum = 0;
					this.$forceUpdate();
					console.log(res.errMsg);
					console.log(res.errCode);
				});
				if (this.list[index].clickNum == 12) {
					// this.list[index].clickNum = 1;
					this.submit();
				}
				this.$forceUpdate();
				
			},
			openModel() {
				if (this.list.length == 0) {
					uni.navigateBack();
				} else {
					this.$refs.modal.open();
				}
			},
			confirm() {
				this.$refs.modal.close();
				uni.navigateBack();
			},
		}
	};
</script>
<style lang="scss" scoped>
	.intensify {
		margin: 15rpx 0 0;
		background: #fff;
		border-radius: 10rpx;
		.intensify_title {
			padding: 20rpx;
			border-bottom: 1px solid #eeeeee;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #333333;
			.title_content {
				font-size: 20rpx;
				font-weight: 500;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				overflow: hidden;
				-webkit-line-clamp: 1;
			}
			.title_operate {
				display: flex;
				.title_operate_1 {
					width: 100rpx;
					height: 30rpx;
					line-height: 27rpx;
					text-align: center;
					background: #4087FD;
					border-radius: 15rpx;
					font-size: 15rpx;
					color: #fff;
				}
				.title_operate_2 {
					color: #4087FD;
					font-size: 18rpx;
					margin-left: 20rpx;
					font-weight: 500;
				}
			}
		}
		.forget_list {
			padding: 0 20rpx;
			.forget_item {
				padding: 25rpx 0;
				border-bottom: 1px solid #eeeeee;
				.item_content {
					font-size: 18rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #666666;
					line-height: 26rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					.see_word {
						display: flex;
						align-items: center;
						justify-content: space-between;
						.see_word_left {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							// font-weight: bold;
							color: #333333;
							display: flex;align-items: center;
						}
						.select_word_explain {
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							// color: #999;
							color: #333;
							margin-left: 90rpx;
						}
						.select_word {
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							// color: #4087FD;
						}
						.see_img {
							width: 25rpx;
							height: 25rpx;
							margin-left: 13rpx;
						}
					}
				}
			}
			.no_line {
				border-bottom: 1px solid transparent;
			}
		}
	}
	.tabs {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0rpx 135rpx;
		.tabs_item {
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #333333;
			padding: 20rpx 0;
			position: relative;
		}
		.active_item {
			color: #4087FD;
			font-weight: bold;
		}
		.tabs_line {
			display: inline-block;
			width: 31rpx;
			height: 5rpx;
			background: #4087FD;
			border-radius: 6rpx;
			position: absolute;
			left: 50%;
			bottom: 0;
			transform: translateX(-50%);
		}
	}
	
	.content_img {
		width: 100%;
		height: 219rpx;
		margin-top: 20rpx;
		image {
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
		}
	}
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto !important;
	}

	.platformMessage_flex_0 {
		background: #fff;
		width: 100%;
		height: 64rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.platformMessage_fd0_0_c1_c0 {
		font-size: 25rpx;
		font-weight: 500;
		color: #333333;
		line-height: 64rpx;
	}

	.platformMessage_fd0_0_c0_c0 {
		font-size: 25rpx;
		color: #333;
	}

	.platformMessage_fd0_0_c0 {
		width: 50rpx;
		height: 50rpx;
	}

	.platformMessage_fd0_0 {
		padding: 0rpx 25rpx 0rpx 25rpx;
	}

	.platformMessage_flex_1 {
		// margin: 16rpx 25rpx 16rpx 25rpx;
		// background: #fff;
		// border-radius: 10rpx;
		padding: 0 25rpx;
	}

	.platformMessage_fd1_0_c2 {
		font-size: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 25rpx;
	}

	.platformMessage_fd1_0_c1 {
		margin: 10rpx 0rpx 0rpx 0rpx;
		font-size: 18rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #999999;
		line-height: 26rpx;
		// -webkit-line-clamp: 2;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// display: -webkit-box;
		// -webkit-box-orient: vertical;
	}

	.platformMessage_fd1_0_c0 {
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #333333;
		// line-height: 45rpx;
		// -webkit-line-clamp: 1;
		// overflow: hidden;
		// text-overflow: ellipsis;
		// display: -webkit-box;
		// -webkit-box-orient: vertical;
	}

	.platformMessage_fd1_0 {
		// background: #fff;
		width: 100%;
		padding: 20rpx 25rpx 20rpx 25rpx;
		border-bottom: 1px solid #eee;
	}
</style>